package PerlBot::Plugin::Relay;
use strict;
use warnings;
use base 'Class::Component::Plugin';
use POE::Component::IKC::ClientLite;
use Encode qw/encode decode/;

sub relay :Hook('log.relay') {
    my ($self, $c, $args) = @_;

    my $remote = create_ikc_client( 
	port => $self->config->{port},
	name => $self->config->{name},
	timeout => $self->config->{timeout},
	);
    
    my $encoded;
    if ($self->config->{encode} eq 'cp949') {
	$encoded = encode($self->config->{encode}, decode("utf-8", "[".$args->{irc}->server_name."] <".$args->{who}."> ".$args->{what}));
    } else {
	$encoded = encode($self->config->{encode}, decode("cp949", "[".$args->{irc}->server_name."] <".$args->{who}."> ".$args->{what}));
    }
	
    $remote->post_respond( 
	$self->config->{service}->{name}.'/'.$self->config->{service}->{method},
	$encoded);
}

1;
